//
//  IncomingDetailsViewController.m
//  HYApp
//
//  Created by Jianbo Cai on 2020/9/4.
//  Copyright © 2020 Unidax. All rights reserved.
//

#import "IncomingDetailsViewController.h"
#import "HYNetHelper.h"

@interface IncomingDetailsViewController ()

@property (nonatomic, strong) IncomingListEntity *entity;

@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *accountLabel;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UILabel *methodLabel;
@property (weak, nonatomic) IBOutlet UILabel *assetLabel;
@property (weak, nonatomic) IBOutlet UILabel *toLabel;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;
@property (weak, nonatomic) IBOutlet UILabel *refLabel;
@property (weak, nonatomic) IBOutlet UILabel *hashLabel;


@property (weak, nonatomic) IBOutlet UILabel *dateTitle;
@property (weak, nonatomic) IBOutlet UILabel *accountTitle;
@property (weak, nonatomic) IBOutlet UILabel *typeTitle;
@property (weak, nonatomic) IBOutlet UILabel *methodTitle;
@property (weak, nonatomic) IBOutlet UILabel *assetTitle;
@property (weak, nonatomic) IBOutlet UILabel *toTitle;
@property (weak, nonatomic) IBOutlet UILabel *statusTitle;
@property (weak, nonatomic) IBOutlet UILabel *refTitle;
@property (weak, nonatomic) IBOutlet UILabel *hashTitle;

@property (weak, nonatomic) IBOutlet UIButton *downButton;

@end

@implementation IncomingDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.separatorInset = UIEdgeInsetsZero;
    
    
    self.title = JFMainLocalizedString(@"transactions.details");
    self.dateTitle.text = JFMainLocalizedString(@"transactions.date");
    self.typeTitle.text = JFMainLocalizedString(@"transactions.type");
    self.assetTitle.text = JFMainLocalizedString(@"transactions.asset");
    self.accountTitle.text = JFMainLocalizedString(@"myProfile.Account");
    self.toTitle.text = JFMainLocalizedString(@"withdraw.to-address");
    self.statusTitle.text = JFMainLocalizedString(@"transactions.status");
    self.hashTitle.text = JFMainLocalizedString(@"transactions.private_transaction_hash");
    self.refTitle.text = JFMainLocalizedString(@"transactions.ref_id");
    self.methodTitle.text = self.entity.isDeposit ? JFMainLocalizedString(@"deposit.method") : JFMainLocalizedString(@"withdraw.method");
    [self.downButton setTitle:JFMainLocalizedString(@"Download") forState:UIControlStateNormal];
    
    [self requestDetails];
}

- (void)requestDetails {
    WEAKSELF
    [HYNetHelper transactions2:self.transfer_id callback:^(JFResultVo *resultVo) {
        if (!resultVo.errorNo) {
            weakSelf.entity = [IncomingListEntity yy_modelWithDictionary:resultVo.results];
            weakSelf.methodLabel.text = weakSelf.entity.method;
            weakSelf.toLabel.text = weakSelf.entity.destination;
            weakSelf.dateLabel.text = weakSelf.entity.date;
            weakSelf.accountLabel.text = [weakSelf.entity.account_label getAccountString];
            weakSelf.typeLabel.text = weakSelf.entity.isDeposit ? JFMainLocalizedString(@"deposit.deposit") : JFMainLocalizedString(@"withdraw.withdraw");
            if ([weakSelf.entity.type rangeOfString:@"FIAT"].location != NSNotFound) {
                weakSelf.assetLabel.text = [NSString stringWithFormat:@"%@ %@", MoneyFormat(weakSelf.entity.amount), weakSelf.entity.asset_symbol];
            }else {
                weakSelf.assetLabel.text = [NSString stringWithFormat:@"%@ %@", weakSelf.entity.amount, weakSelf.entity.asset_symbol];
            }
            weakSelf.statusLabel.text = weakSelf.entity.status;
            weakSelf.refLabel.text = weakSelf.entity.ref_id;
            
            
            [weakSelf.tableView reloadData];
        }
    }];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.row) {
        case 3:
            return self.entity.isDigital ? 0 : 75;
            break;
        case 4:
            return self.entity.destination ? 75 : 0;
            break;
        case 8:
            return self.entity.isDigital ? 75 : 0;
            break;
        default:
            break;
    }
    return 75;
}

- (IBAction)downAction:(id)sender {
    UIImage *image = [UIImage getImageWithScrollView:self.tableView];
    UIImageWriteToSavedPhotosAlbum(image, nil, nil,nil);;
}


@end
